/**
 * Created by walkman on 2017/7/15.
 */

angular.module('WfbPlatformApp')
  .factory('teamService', ['$http', '$q', function ($http, $q) {

    return {

      activeMember: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'team/active_member',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
            // else {
            //   deferred.reject("failed to fetch  data");
            // }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getInactiveMember: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'team/inactive_members',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getInactiveChildren: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'team/inactiveChildren',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getInvestRecord: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'team/invest_record',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getTeamLevel: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'team/level',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getChildren: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'team/children',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      getTeamOutline: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'team/outline',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

      //获取我的邀请内容
      getInviteContent: function (paramData) {
        var deferred = $q.defer();
        $http({
          method: 'POST',
          url: 'user/getInviteContent',
          data: paramData
        }).then(function success(result) {
            if (result.data.retCode == '1') {
              // 请求成功
              deferred.resolve(result.data);
            }
          },
          function error(error) {
            deferred.reject(error);//请求失败
          }
        );
        return deferred.promise;//返回承诺
      },

    };

  }]);
